--HTDictionaryTest
--[[
    HTDictionary：字典
--]]

require 'HTDictionary'

----------//测试 Dictionary//----------
EventType = {
    Game_Start = 1,
    Game_Setting = 2,
    Game_Quit = 3,
    Battle_Start = 4,
    Battle_Success = 5,
    Battle_Failure = 6,
}

function main()
    --创建
    eventContainner = Dictionary:New(type(EventType.Game_Start),type(function()end))
    --添加
    local func1 = function()print('事件：游戏开始！')end
    local func2 = function()print('事件：游戏设置！')end
    eventContainner:Add(EventType.Game_Start,func1)
    eventContainner:Add(EventType.Game_Setting,func2)
    eventContainner:Add(EventType.Game_Quit,function()print('事件：游戏退出！')end)
    eventContainner:Add(EventType.Battle_Start,function()print('事件：战斗开始！')end)
    eventContainner:Add(EventType.Battle_Success,function()print('事件：战斗胜利！')end)
    eventContainner:Add(EventType.Battle_Failure,function()print('事件：战斗失败！')end)
    print(string.format('当前列表中共有 %d 个键值对，key：%s；value：%s',eventContainner:Count(),eventContainner:KeyType(),eventContainner:ValueType()))
    --遍历
    local iterator = eventContainner:GetIterator() --获取迭代器
    local eventType,eventFunc = iterator() --执行迭代器方法
    while eventFunc ~= nil do
        print('事件：'..eventType)
        eventFunc()
        eventType,eventFunc = iterator()
    end
    --判断包含
    print(string.format('%s key值 Battle_Success',eventContainner:ContainsKey(EventType.Battle_Success) and '包含' or '不包含'))
    print(string.format('%s value值 (key: Game_Start)',eventContainner:ContainsValue(func1) and '包含' or '不包含'))
    --删除
    eventContainner:Remove(EventType.Game_Start)
    eventContainner:Remove(EventType.Battle_Success)
    print('删除 Game_Start 和 Battle_Success 后，剩余键值对个数：'..eventContainner:Count())
    print(string.format('%s key值 Battle_Success',eventContainner:ContainsKey(EventType.Battle_Success) and '包含' or '不包含'))
    print(string.format('%s value值 (key: Game_Start)',eventContainner:ContainsValue(func1) and '包含' or '不包含'))
    --清空
    eventContainner:Clear()
    print('清空后，剩余键值对个数：'..eventContainner:Count())
    print(string.format('%s key值 Battle_Failure',eventContainner:ContainsKey(EventType.Battle_Failure) and '包含' or '不包含'))
    print(string.format('%s value值 (key: Game_Setting)',eventContainner:ContainsValue(func2) and '包含' or '不包含'))
end

main()